﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Locallab.Ack999Helper.BusinessContextReader
{
    [Serializable]
    internal class EdiSegment
    {
        public string Name { get; set; }
        public bool IsBusinessID { get; set; }
        public string Data { get; set; }
        public int LineNumber { get; set; }
        public int FileLineNumber { get; set; }
        private string strTransaction;
        public string ElementDelimiter { get; set; }


        public EdiSegment(string strData, string strElementDelimiter, string strTransactionType, int nLineNumber)
        {
            this.Data = strData;
            this.strTransaction = strTransactionType;
            this.ElementDelimiter = strElementDelimiter;
            this.LineNumber = nLineNumber;
            this.IsBusinessID = false;

            InitalizeBusinessID();
        }

        private void InitalizeBusinessID()
        {
            this.Name = this.Data.Substring(0, this.Data.IndexOf(this.ElementDelimiter));

            if (this.Name == "ISA" || this.Name == "IEA" || this.Name == "GS" ||
                this.Name == "GE" || this.Name == "ST" || this.Name == "SE")
            {
                this.IsBusinessID = true;
                return;
            }

            switch (this.strTransaction)
            {
                case "005010X222":
                case "005010X222E1":
                case "005010X222A1":
                case "005010X223":
                case "005010X223A1":
                case "005010X223E1":
                case "005010X223A2":
                case "005010X224":
                case "005010X224A1":
                case "005010X224E1":
                case "005010X224A2":
                case "004010X098A1":
                    {
                        if (this.Name == "HL" || this.Name == "CLM")
                            this.IsBusinessID = true;                        
                    }
                    break;

                default:
                    this.IsBusinessID = false;
                    break;                        
            }            
        }

    }

    
}
